﻿using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using WideSliderManaged;

// Token: 0x02000002 RID: 2
public class AnimationKeyInfoEx
{
	// Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00000250
	public static bool GetInfo(object obj, string name, float rate, ref Vector3 value, byte type)
	{
		SliderModifier.EnsureSliderModifierActivate();
		AnimationKeyInfo anim = obj as AnimationKeyInfo;
		List<AnimationKeyInfo.AnmKeyInfo> list = null;
		if (!AnimationKeyInfoEx.GetDictInfo(anim).TryGetValue(name, out list))
		{
			global::Debug.Log(name + "が見つからない");
			return false;
		}
		if (type == 0)
		{
			if (rate < 0f)
			{
				value = list[0].pos - (list[list.Count - 1].pos - list[0].pos) * Mathf.Abs(rate);
			}
			else if (rate > 1f)
			{
				value = list[list.Count - 1].pos + (list[list.Count - 1].pos - list[0].pos) * Mathf.Abs(rate - 1f);
			}
			else if (rate == 0f)
			{
				value = list[0].pos;
			}
			else if (rate == 1f)
			{
				value = list[list.Count - 1].pos;
			}
			else
			{
				float num = (float)(list.Count - 1) * rate;
				int num2 = Mathf.FloorToInt(num);
				float t = num - (float)num2;
				value = Vector3.Lerp(list[num2].pos, list[num2 + 1].pos, t);
			}
		}
		else if (type == 1)
		{
			if (rate < 0f)
			{
				if (LimitConfig.NoRotateLimit)
				{
					value = AnimationKeyInfoEx.CalcRot(list, rate);
				}
				else
				{
					value = list[0].rot;
				}
			}
			else if (rate > 1f)
			{
				if (LimitConfig.NoRotateLimit)
				{
					value = AnimationKeyInfoEx.CalcRot(list, rate);
				}
				else
				{
					value = list[list.Count - 1].rot;
				}
			}
			else if (rate == 0f)
			{
				value = list[0].rot;
			}
			else if (rate == 1f)
			{
				value = list[list.Count - 1].rot;
			}
			else
			{
				float num3 = (float)(list.Count - 1) * rate;
				int num4 = Mathf.FloorToInt(num3);
				float t2 = num3 - (float)num4;
				value.x = Mathf.LerpAngle(list[num4].rot.x, list[num4 + 1].rot.x, t2);
				value.y = Mathf.LerpAngle(list[num4].rot.y, list[num4 + 1].rot.y, t2);
				value.z = Mathf.LerpAngle(list[num4].rot.z, list[num4 + 1].rot.z, t2);
			}
		}
		else if (rate < 0f)
		{
			value = list[0].scl - (list[list.Count - 1].scl - list[0].scl) * Mathf.Abs(rate);
		}
		else if (rate > 1f)
		{
			value = list[list.Count - 1].scl + (list[list.Count - 1].scl - list[0].scl) * Mathf.Abs(rate - 1f);
		}
		else if (rate == 0f)
		{
			value = list[0].scl;
		}
		else if (rate == 1f)
		{
			value = list[list.Count - 1].scl;
		}
		else
		{
			float num5 = (float)(list.Count - 1) * rate;
			int num6 = Mathf.FloorToInt(num5);
			float t3 = num5 - (float)num6;
			value = Vector3.Lerp(list[num6].scl, list[num6 + 1].scl, t3);
		}
		return true;
	}

	// Token: 0x06000002 RID: 2 RVA: 0x00002474 File Offset: 0x00000674
	public static bool GetInfo(object obj, string name, float rate, ref Vector3[] value, bool[] flag)
	{
		SliderModifier.EnsureSliderModifierActivate();
		AnimationKeyInfo anim = obj as AnimationKeyInfo;
		if (value.Length != 3 || flag.Length != 3)
		{
			return false;
		}
		List<AnimationKeyInfo.AnmKeyInfo> list = null;
		if (!AnimationKeyInfoEx.GetDictInfo(anim).TryGetValue(name, out list))
		{
			global::Debug.Log(name + "が見つからない");
			return false;
		}
		if (flag[0])
		{
			if (rate < 0f)
			{
				value[0] = list[0].pos - (list[list.Count - 1].pos - list[0].pos) * Mathf.Abs(rate);
			}
			else if (rate > 1f)
			{
				value[0] = list[list.Count - 1].pos + (list[list.Count - 1].pos - list[0].pos) * Mathf.Abs(rate - 1f);
			}
			else if (rate == 0f)
			{
				value[0] = list[0].pos;
			}
			else if (rate == 1f)
			{
				value[0] = list[list.Count - 1].pos;
			}
			else
			{
				float num = (float)(list.Count - 1) * rate;
				int num2 = Mathf.FloorToInt(num);
				float t = num - (float)num2;
				value[0] = Vector3.Lerp(list[num2].pos, list[num2 + 1].pos, t);
			}
		}
		if (flag[1])
		{
			if (rate < 0f)
			{
				if (LimitConfig.NoRotateLimit || (!flag[0] && !flag[2]))
				{
					value[1] = AnimationKeyInfoEx.CalcRot(list, rate);
				}
				else
				{
					value[1] = list[0].rot;
				}
			}
			else if (rate > 1f)
			{
				if (LimitConfig.NoRotateLimit || (!flag[0] && !flag[2]))
				{
					value[1] = AnimationKeyInfoEx.CalcRot(list, rate);
				}
				else
				{
					value[1] = list[list.Count - 1].rot;
				}
			}
			else if (rate == 0f)
			{
				value[1] = list[0].rot;
			}
			else if (rate == 1f)
			{
				value[1] = list[list.Count - 1].rot;
			}
			else
			{
				float num3 = (float)(list.Count - 1) * rate;
				int num4 = Mathf.FloorToInt(num3);
				float t2 = num3 - (float)num4;
				value[1].x = Mathf.LerpAngle(list[num4].rot.x, list[num4 + 1].rot.x, t2);
				value[1].y = Mathf.LerpAngle(list[num4].rot.y, list[num4 + 1].rot.y, t2);
				value[1].z = Mathf.LerpAngle(list[num4].rot.z, list[num4 + 1].rot.z, t2);
			}
		}
		if (flag[2])
		{
			if (rate < 0f)
			{
				value[2] = list[0].scl - (list[list.Count - 1].scl - list[0].scl) * Mathf.Abs(rate);
			}
			else if (rate > 1f)
			{
				value[2] = list[list.Count - 1].scl + (list[list.Count - 1].scl - list[0].scl) * Mathf.Abs(rate - 1f);
			}
			else if (rate == 0f)
			{
				value[2] = list[0].scl;
			}
			else if (rate == 1f)
			{
				value[2] = list[list.Count - 1].scl;
			}
			else
			{
				float num5 = (float)(list.Count - 1) * rate;
				int num6 = Mathf.FloorToInt(num5);
				float t3 = num5 - (float)num6;
				value[2] = Vector3.Lerp(list[num6].scl, list[num6 + 1].scl, t3);
			}
		}
		return true;
	}

	// Token: 0x06000003 RID: 3 RVA: 0x000028FC File Offset: 0x00000AFC
	private static Vector3 CalcRot(List<AnimationKeyInfo.AnmKeyInfo> list, float rate)
	{
		Vector3 rot = list[0].rot;
		Vector3 rot2 = list[1].rot;
		Vector3 rot3 = list[list.Count - 1].rot;
		Vector3 vector = rot2 - rot;
		Vector3 vector2 = rot3 - rot;
		bool flag = vector.x >= 0f;
		bool flag2 = vector.y >= 0f;
		bool flag3 = vector.z >= 0f;
		if (vector2.x > 0f && !flag)
		{
			vector2.x -= 360f;
		}
		else if (vector2.x < 0f && flag)
		{
			vector2.x += 360f;
		}
		if (vector2.y > 0f && !flag2)
		{
			vector2.y -= 360f;
		}
		else if (vector2.y < 0f && flag2)
		{
			vector2.y += 360f;
		}
		if (vector2.z > 0f && !flag3)
		{
			vector2.z -= 360f;
		}
		else if (vector2.z < 0f && flag3)
		{
			vector2.z += 360f;
		}
		if (rate < 0f)
		{
			return rot - vector2 * Mathf.Abs(rate);
		}
		return rot3 + vector2 * Mathf.Abs(rate - 1f);
	}

	// Token: 0x06000004 RID: 4 RVA: 0x00002A8A File Offset: 0x00000C8A
	private static Dictionary<string, List<AnimationKeyInfo.AnmKeyInfo>> GetDictInfo(AnimationKeyInfo anim)
	{
		return AnimationKeyInfoEx.f_dictInfo.GetValue(anim) as Dictionary<string, List<AnimationKeyInfo.AnmKeyInfo>>;
	}

	// Token: 0x04000001 RID: 1
	private static FieldInfo f_dictInfo = typeof(AnimationKeyInfo).GetField("dictInfo", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
}
